package com.sangu.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.sangu.enums.AppCodeEnum;
import lombok.Data;

import java.io.Serializable;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R<T> implements Serializable {

    private Integer code;
    private String msg;
    private T data;

    public R() {
        this.code = AppCodeEnum.SUCCESS.getCode();
        this.msg = AppCodeEnum.SUCCESS.getMsg();
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //静态方法
    public static R ok(Object data){
        R<Object> r = new R<>();
        if (data!=null){
            r.setData(data);
        }
        return r;
    }



    public static R success(int code,String msg){
        R<Object> r = new R<>();
        return r;
    }



}
